﻿
/// < reference path='lib/jquery.min.js' />
/// <reference path='ol3/ol-whitespace.js' />  //这个貌似只认单引号

goog.provide('ol.control.LiuGNavigation');

goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.control.Control');
goog.require('ol.control.LiuGForm');
goog.require('ol.css');
goog.require('ol.pointer.PointerEventHandler');



/**
 * Create a control that adds a Navigation button, 
 */
ol.control.LiuGNavigation = function (opt_options)
{
    var options = goog.isDef(opt_options) ? opt_options : {};


    var className = goog.isDef(options.className) ? options.className :
        'menu';

    var element = goog.dom.createDom(goog.dom.TagName.DIV, {
        'class': className,'id':'fd'
    });

    var box = goog.dom.createDom(goog.dom.TagName.DIV, { 'class': 'box', 'style': 'display:none' });

    //var range = goog.dom.createDom(goog.dom.TagName.INPUT, { 'type': 'range' }, '选择框');

    //goog.dom.appendChild(element, range);

    var t1 = goog.dom.createDom(goog.dom.TagName.A, {'class':'t1','href':'javascript:'});
    var t2 = goog.dom.createDom(goog.dom.TagName.A, { 'class': 't2', 'href': 'javascript:' });
    var t3 = goog.dom.createDom(goog.dom.TagName.A, { 'class': 't3', 'href': 'javascript:' });
    var t4 = goog.dom.createDom(goog.dom.TagName.A, { 'class': 't4', 'href': 'javascript:' });
    var t5 = goog.dom.createDom(goog.dom.TagName.A, { 'class': 't5', 'href': 'javascript:' });
    var t6= goog.dom.createDom(goog.dom.TagName.A, { 'class': 't6', 'href': 'javascript:' });
    
    goog.dom.appendChild(box, t1);
    goog.dom.appendChild(box, t2);
    goog.dom.appendChild(box, t3);
    //goog.dom.appendChild(box, t4);
    //goog.dom.appendChild(box, t5);
    //goog.dom.appendChild(box, t6);

    goog.dom.appendChild(element, box);


    goog.events.listen(t2, goog.events.EventType.CLICK, function ()
    {
        var layerControl = new ol.control.LiuGLayerManagement(
            {
                title: '图层管理器',
                width: 200,
                height: 400,
                minWidth: 180,
                minHeight: 100,
                top: 50,
                right:10
            });
        var map = this.getMap();
        if (goog.isNull(map))
        {
            return;
        }
        map.addControl(layerControl);
    },false, this);


    //添加双击全屏的效果，但此效果只有部分最新的浏览器支持
    goog.events.listen(element, goog.events.EventType.DBLCLICK, this.handleClick_, false, this);


    this.Drag(element);


    goog.base(this, {
        element: element,
        target: options.target,
    });
};
goog.inherits(ol.control.LiuGNavigation, ol.control.Control);

ol.control.LiuGNavigation.prototype.setMap = function (map)
{
    goog.base(this, 'setMap', map);
    Toggle();
}

function Toggle()
{    //可以把参数直接传递进来
    var box = $('.menu .box');
    $('.menu').hover(
        function ()
        {
            box.stop().show(400);
        },
    function ()
    {
        box.stop().hide(150);
    })
}

ol.control.LiuGNavigation.prototype.Drag = function (element)
{
    var box = element;
    box.onmousedown = function (event)
    {
        var e = event || window.event,
        t = e.target || e.srcElement,
        //鼠标按下时的坐标x1,y1
        x1 = e.clientX,
        y1 = e.clientY,
        //鼠标按下时的左右偏移量
        dragLeft = this.offsetLeft,
        dragTop = this.offsetTop;
        document.onmousemove = function (event)
        {
            var e = event || window.event,
            t = e.target || e.srcElement,
            //鼠标移动时的动态坐标
            x2 = e.clientX,
            y2 = e.clientY,
            //鼠标移动时的坐标的变化量
            x = x2 - x1,
            y = y2 - y1;
            box.style.left = (dragLeft + x) + 'px';
            box.style.top = (dragTop + y) + 'px';
        }
        document.onmouseup = function ()
        {
            this.onmousemove = null;
        }
    }
}


//全屏
ol.control.LiuGNavigation.prototype.handleClick_ = function (pointerEvent)
{
    if (!googx.dom.fullscreen.isSupported())
    {
        return;
    }
    //pointerEvent.browserEvent.preventDefault();
    var map = this.getMap();
    if (goog.isNull(map))
    {
        return;
    }
    if (googx.dom.fullscreen.isFullScreen())
    {
        googx.dom.fullscreen.exitFullScreen();
    } else
    {
        var target = map.getTarget();
        goog.asserts.assert(goog.isDefAndNotNull(target));
        var element = goog.dom.getElement(target);
        goog.asserts.assert(goog.isDefAndNotNull(element));
        if (this.keys_)
        {
            googx.dom.fullscreen.requestFullScreenWithKeys(element);
        } else
        {
            googx.dom.fullscreen.requestFullScreen(element);
        }
    }
};







